#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/10/26 19:18
# @Author  : Crissu
# @Site    : 
# @File    : CreateMap.py
# @Software: PyCharm
import xlrd

'''
    读取idx列表
'''
def readLstXls(path):
    '''
    :param path: .xls 路径
    :return: idx2classMap(key:idx, value:name)
    '''
    workbook = xlrd.open_workbook(path)  # 打开工作簿
    sheets = workbook.sheet_names()  # 获取工作簿中的所有表格
    worksheet = workbook.sheet_by_name(sheets[0])  # 获取工作簿中所有表格中的的第一个表格
    idx2classMap = {}  # key:分类；value:正确个数
    # 计算正确个数和分类总个数
    for i in range(0, worksheet.nrows):
        idx = int(worksheet.cell_value(i, 0))
        name = str(worksheet.cell_value(i, 2)).split("\\")[0]
        idx2classMap[idx] = name

    return idx2classMap

if __name__ == '__main__':
    book_name_xls = 'test.xls'
    idx2classMap = readLstXls(book_name_xls)
    print(idx2classMap)